package com.cssiot.weixin.basic.util;

import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext;

public class StartServer {
    public static void main(String[] args) {  
      /*  try {  
            // 服务器的监听端口  
            Server server = new Server(8080);  
            // 关联一个已经存在的上下文  
            WebAppContext context = new WebAppContext();  
            context.setContextPath("/wx");  
            // 设置描述符位置  
            context.setDescriptor("./src/main/webapp/WEB-INF/web.xml");  
            // 设置Web内容上下文路径  
            context.setResourceBase("./src/main/webapp");  
            // 设置上下文路径  
            context.setContextPath("/simple");  
            context.setParentLoaderPriority(true);  
            server.setHandler(context);  
            // 启动  
            server.start();  
            server.join();  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  */
    	
    	
    	 Server server = new Server();  
         Connector connector = new SelectChannelConnector();  
         connector.setPort(8080);                       
         server.setConnectors(new Connector[] { connector });  
         WebAppContext webAppContext = new WebAppContext("./src/main/webapp/","/wx");  
         webAppContext.setContextPath("/wx");  
         webAppContext.setDescriptor("./src/main/webapp/WEB-INF/web.xml");  
         webAppContext.setResourceBase("./src/main/webapp/");  
         webAppContext.setDisplayName("wx");  
         webAppContext.setClassLoader(Thread.currentThread().getContextClassLoader());  
         webAppContext.setConfigurationDiscovered(true);  
         webAppContext.setParentLoaderPriority(true);  
         server.setHandler(webAppContext);  
         System.out.println(webAppContext.getContextPath());  
         System.out.println(webAppContext.getDescriptor());  
         System.out.println(webAppContext.getResourceBase());  
         System.out.println(webAppContext.getBaseResource());  
   
         try {  
             server.start();
             server.join();  
         } catch (Exception e) {  
             e.printStackTrace();  
         }  
         System.out.println("server is  start");  
    	
    }  

}
